from django import template

register = template.Library()


@register.filter
def get_permission_group(codename):
    return codename.split('.')[0]


@register.filter
def get_permission_level(codename, level=0):
    try:
        return codename.split('.')[level]
    except IndexError:
        return ''


@register.filter
def has_permission_level(codename, level):
    """检查权限码是否达到指定层级深度"""
    return len(codename.split('.')) > level
